package com.bd.myprotolib.bean;

import com.hailiao.hlbdcore.annotation.HLBDFieldOut4;
import com.hailiao.hlbdcore.base.BaseOutBean;
import com.hailiao.hlbdcore.constant.BDErrorType;
import com.hailiao.hlbdcore.constant.ConversionType;

import org.jetbrains.annotations.NotNull;

/**
 * 自检信息回复
 * @Author: D10NG
 * @Time: 2021/12/3 15:24
 */
public class ZJXX_Bean extends BaseOutBean {

    /**
     * start：表示从第几个byte开始处理
     * itemLength：表示当前参数所占有的字节长度
     */
    @HLBDFieldOut4(start = 7, itemLength = 4, conversion = ConversionType.STRING_INT, name = "用户地址，仅为0000000")
    public String address = "0000000";

    /**
     * isIgnore：忽略自动解析，在复写中手动解析
     */
    @HLBDFieldOut4(isIgnore = true, start = 100001, name = "智能卡处理状态/保密模块状态")
    public boolean cardStatus0 = false;

    @HLBDFieldOut4(isIgnore = true, start = 100002, name = "ID 号状态")
    public boolean cardStatus1 = false;

    @HLBDFieldOut4(isIgnore = true, start = 100003, name = "校验码状态/IC 卡状态")
    public boolean cardStatus2 = false;

    @HLBDFieldOut4(isIgnore = true, start = 100004, name = "序列号状态")
    public boolean cardStatus3 = false;

    @HLBDFieldOut4(isIgnore = true, start = 100005, name = "卡类型/双口RAM状态")
    public boolean cardStatus4 = false;

    @HLBDFieldOut4(isIgnore = true, start = 100006, name = "智能卡数据状态")
    public boolean cardStatus5 = false;

    @HLBDFieldOut4(isIgnore = true, start = 100007, name = "智能卡状态")
    public boolean cardStatus6 = false;

    @HLBDFieldOut4(isIgnore = true, start = 200001, name = "天线状态")
    public boolean deviceStatus0 = false;

    @HLBDFieldOut4(isIgnore = true, start = 200002, name = "通道状态")
    public boolean deviceStatus1 = false;

    @HLBDFieldOut4(isIgnore = true, start = 200003, name = "主板状态")
    public boolean deviceStatus2 = false;

    @HLBDFieldOut4(start = 13, itemLength = 1, name = "电池电量")
    public int power = 0;

    @HLBDFieldOut4(isIgnore = true, start = 300001, name = "是否可以入站")
    public boolean inStatus0 = false;

    @HLBDFieldOut4(isIgnore = true, start = 300002, name = "抑制状态")
    public boolean inStatus1 = false;

    @HLBDFieldOut4(start = 15, itemLength = 1, name = "波速1功率", valueRange = "0~4")
    public int beam1 = 0;

    @HLBDFieldOut4(start = 16, itemLength = 1, name = "波速2功率", valueRange = "0~4")
    public int beam2 = 0;

    @HLBDFieldOut4(start = 17, itemLength = 1, name = "波速3功率", valueRange = "0~4")
    public int beam3 = 0;

    @HLBDFieldOut4(start = 18, itemLength = 1, name = "波速4功率", valueRange = "0~4")
    public int beam4 = 0;

    @HLBDFieldOut4(start = 19, itemLength = 1, name = "波速5功率", valueRange = "0~4")
    public int beam5 = 0;

    @HLBDFieldOut4(start = 20, itemLength = 1, name = "波速6功率", valueRange = "0~4")
    public int beam6 = 0;

    public ZJXX_Bean() {
        super(false, BDErrorType.NONE, "$ZJXX<s(2)><p(4)><p(1)><p(1)><p(1)><p(1)><p(1)>..<h(1)>");
    }

    @Override
    public void setValue4(@NotNull byte[] data) {
        // 传递进来的是一整条数据
        // 先用父方法将自动解析的参数处理了先
        super.setValue4(data);
        // 手动解析参数
        try {
            byte cardStatus = data[11];
            cardStatus0 = (cardStatus & 0x01) == 0x01;
            cardStatus1 = (cardStatus & 0x02) == 0x02;
            cardStatus2 = (cardStatus & 0x04) == 0x04;
            cardStatus3 = (cardStatus & 0x08) == 0x08;
            cardStatus4 = (cardStatus & 0x10) == 0x10;
            cardStatus5 = (cardStatus & 0x20) == 0x20;
            cardStatus6 = (cardStatus & 0x40) == 0x40;
            byte deviceStatus = data[12];
            deviceStatus0 = (deviceStatus & 0x01) == 0x01;
            deviceStatus1 = (deviceStatus & 0x02) == 0x02;
            deviceStatus2 = (deviceStatus & 0x04) == 0x04;
            byte inStatus = data[14];
            inStatus0 = (inStatus & 0x01) == 0x01;
            inStatus1 = (inStatus & 0x02) == 0x02;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
